#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include "cmd.h"
#include "parse.h"
void read_line(char *line, int size);
int main()
{
    while (1)
    {
        int cmdc;
        char line[100];
        read_line(line, sizeof(line));
        struct cmd cmdv[10];
        cmdc = parse_pipe_cmd(line, cmdv);
        if (cmdc == 1 && builtin_cmd(&cmdv[0]))
            continue;
        pid_t pid = fork();
        if (pid == 0)
            exec_pipe_cmd(cmdc, cmdv);
        wait(NULL);
    }
    return 0;
}

void read_line(char *line, int size)
{
    write(1, "> ", 2);
    int count = read(0, line, size);
    assert(line[count - 1] == '\n');
    line[count - 1] = 0;
}
